package com.ag.improvedjava.utils.comparators;

import java.util.Comparator;

public final class CompoundComparator<T> implements Comparator<T> {
	
	private final Comparator<T> primary;
	private final Comparator<T> secondary;
	
	public CompoundComparator(Comparator<T> primary, Comparator<T> secondary) {
		this.primary = primary;
		this.secondary = secondary;
	}
	
	@Override
	public int compare(T x, T y) {
		int primaryResult = primary.compare(x, y);
		if (primaryResult != 0) {
			return primaryResult;
		}
		return secondary.compare(x, y);
	}
}